package com.swhysc.information.controller;

import com.swhysc.information.common.model.GridView;
import com.swhysc.information.common.model.ResultBody;
import com.swhysc.information.entity.InformationDataColumnEx;
import com.swhysc.information.service.IInformationDataColumnExService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author zmq
 * @Date 2022/10/14 9:37
 * @Description
 */
@RestController
@RequestMapping("/api/infor/data/column/experiment")
@Api(value = "InformationDataColumnExController", tags = "资讯数据表字段(实验室)")
public class InformationDataColumnExController {

    @Autowired
    private IInformationDataColumnExService iInformationDataColumnService;

    @GetMapping("/search/list")
    @ApiOperation(value = "首页检索", notes = "首页检索")
    public ResultBody<GridView> list(
            @ApiParam("查询条件") @RequestParam(required = false) String queryParam,
            @ApiParam("查询类型 1:表 2:字段") @RequestParam(required = false) String queryType,
            @ApiParam("数据源id") @RequestParam(required = false) String dataSourceIds,
            @ApiParam("目录id") @RequestParam(required = false) String queryDirId,
            @ApiParam(value = "页数") @RequestParam Integer page,
            @ApiParam(value = "行数") @RequestParam Integer size) {
        try {
            Map result = iInformationDataColumnService.getSearchList(queryParam, dataSourceIds, queryType , queryDirId, page, size);
            return ResultBody.success(result);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return ResultBody.failure("查询失败");
        }
    }

    @PostMapping("/create")
    @ApiOperation(value = "新增", notes = "新增")
    public ResultBody create(@RequestBody List<InformationDataColumnEx> informationDataColumns) {
        Boolean result;
        try {
            result = iInformationDataColumnService.create(informationDataColumns);
        } catch (Exception e) {
            return ResultBody.failure(e.getMessage());
        }
        return ResultBody.success(result);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "批量删除", notes = "批量删除")
    public ResultBody create(@ApiParam("字段id") @RequestParam String ids) {
        Map<String, Object> result = null;
        try {
            result = iInformationDataColumnService.delete(ids);
        } catch (Exception e) {
            return ResultBody.failure("删除字段出错");
        }
        return ResultBody.success(result);
    }

}
